import { Component, OnInit } from '@angular/core';
import { HttpService } from '@core/services/http.service';
import { ActivatedRoute, Router } from '@angular/router';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';


@Component({
    selector: 'app-teacrouse',
    templateUrl: './teacrouse.component.html',
    styleUrls: ['./teacrouse.component.less']
})
export class TeacrouseComponent implements OnInit {

    loading = false;
    list: any = [];
    pageSize: number;
    pageIndex = 1;
    IP_PORT = this.Http.IP_PORT;
    total: number;
    token: string;

    user_id = JSON.parse(localStorage.getItem('_user')).user_id;

    style: any = {
        width: '70%'
    };
    constructor(private Http: HttpService,
        private msg: NzMessageService,
        private confirmServ: NzModalService,
        public router: Router,
        private ActiveRoute: ActivatedRoute) { }

    ngOnInit() {
        this.getData();
    }
    getData() {
        this.pageSize = 8;
        this.Http.getCourse({ pi: this.pageIndex, ps: this.pageSize, key: '' }).subscribe(data => {
            this.list = [];
            this.list = this.list.concat(data.list);
            this.total = data.total;
            this.Http.getCListByTechId({ tech_id: this.user_id }).subscribe(res => {
               for (let ylist of this.list) {
                    ylist['isUse'] = false;
                    for (let klist of res['list']) {
                        if (ylist.cour_id == klist.course_id) {
                            ylist.isUse = true;
                        }
                    }
                }
            });
        });

    }

    preview(cour_id, isCloud, isUse) {
        this.router.navigate(['/xiangmu/full/viewcrouse'], { relativeTo: this.ActiveRoute, queryParams: { cour_id: cour_id, isCloud: isCloud, isUse: isUse } });
    }

    QuoteCourseProject(id) {
        this.Http.QuoteCourseProject({ cour_id: id }).subscribe(t => {
            this.msg.info(t.msg);
            // this.getData();
        });
    }
}
